package com.laiketui.common.service.dubbo;

import com.laiketui.common.api.PublicBomService;
import com.laiketui.common.mapper.BomModelMapper;
import com.laiketui.domain.bom.BomModel;
import com.laiketui.domain.vo.BomAddVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PublicBomServiceImpl implements PublicBomService {
    @Autowired
    private BomModelMapper bomModelMapper;

    @Override
    public BomModel selectBomByConfigureId(Integer configureId) {
        if(configureId == null){
            return null;
        }
        BomModel bomModel = new BomModel();
        bomModel.setConfigure_id(configureId);
        BomModel bom = bomModelMapper.selectOne(bomModel);
        return bom;
    }


    @Override
    public void addBom(BomAddVo vo) {
        if(vo.getId() != null){
            BomModel bomModel = new BomModel();
            bomModel.setConfigure_id(vo.getConfigureId());
            bomModel.setBom_value(vo.getBomValue());
            bomModelMapper.insert(bomModel);
        }else{
            BomModel bomModel = new BomModel();
            bomModel.setId(vo.getId());
            bomModel.setBom_value(vo.getBomValue());
            bomModel.setConfigure_id(vo.getConfigureId());
        }
    }
}
